﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace SystemFileWatcher
{
    public partial class Form2 : Form
    {
        SQLiteConnection sqlite_conn;
        SQLiteCommand sqlite_cmd;
        
        

        public Form2()
        {
            InitializeComponent();
            // create a new database connection:
            if (File.Exists("database.db"))
                sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=False;Compress=True;");
            else
            {
                //put error here

            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'databaseDataSet.log' table. You can move, or remove it, as needed.
            //this.logTableAdapter.Fill(this.databaseDataSet.log);

        }

        private void dbQuery_Click(object sender, EventArgs e)
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM log;";
            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd))
            {
                DataSet dataSet = new DataSet();
                try
                {
                    //dataAdapter.Fill(dataSet);
                    DataTable dataTable = new DataTable();
                    
                    dataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                }
                catch (Exception exception)
                {
                   
                }
            }
            sqlite_conn.Close();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dLLToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.logTableAdapter.DLL(this.databaseDataSet.log);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void dLLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM log WHERE extension = \'.dll\';";
            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd))
            {
                DataSet dataSet = new DataSet();
                try
                {
                    //dataAdapter.Fill(dataSet);
                    DataTable dataTable = new DataTable();

                    dataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                }
                catch (Exception exception)
                {

                }
            }
            sqlite_conn.Close();

        }

        private void tXTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM log WHERE extension = \'.txt\';";
            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd))
            {
                DataSet dataSet = new DataSet();
                try
                {
                    //dataAdapter.Fill(dataSet);
                    DataTable dataTable = new DataTable();

                    dataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                }
                catch (Exception exception)
                {

                }
            }
            sqlite_conn.Close();
        }

        private void eXEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM log WHERE extension = \'.exe\';";
            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd))
            {
                DataSet dataSet = new DataSet();
                try
                {
                    //dataAdapter.Fill(dataSet);
                    DataTable dataTable = new DataTable();

                    dataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                }
                catch (Exception exception)
                {

                }
            }
            sqlite_conn.Close();
        }

        private void rTFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM log WHERE extension = \'.rtf\';";
            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd))
            {
                DataSet dataSet = new DataSet();
                try
                {
                    //dataAdapter.Fill(dataSet);
                    DataTable dataTable = new DataTable();

                    dataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                }
                catch (Exception exception)
                {

                }
            }
            sqlite_conn.Close();
        }

        private void dOCXToolStripMenuItem_Click(object sender, EventArgs e)//later revision should include a helper method that passes extension as parameter.
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM log WHERE extension = \'.docx\';";
            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd))
            {
                DataSet dataSet = new DataSet();
                try
                {
                    //dataAdapter.Fill(dataSet);
                    DataTable dataTable = new DataTable();

                    dataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                }
                catch (Exception exception)
                {

                }
            }
            sqlite_conn.Close();
        }

        private void deleteRowsButton_Click(object sender, EventArgs e)
        {
            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "DELETE FROM log;";
            sqlite_cmd.ExecuteNonQuery();
          
            sqlite_conn.Close();

        }

       

       
    }
}
